//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.tool.RuntimeException;


import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.Statements;
import net.sf.jsqlparser.statement.delete.Delete;
import net.sf.jsqlparser.statement.insert.Insert;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.update.Update;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;

import java.util.Iterator;

public abstract class JsqlParserSupport {
    protected final Log logger = LogFactory.getLog(this.getClass());

    public JsqlParserSupport() {
    }

    public String parserSingle(String sql, Object obj) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("original SQL: " + sql);
        }

        try {
            Statement statement = JsqlParserGlobal.parse(sql);
            return this.processParser(statement, 0, sql, obj);
        } catch (JSQLParserException var4) {
            JSQLParserException e = var4;
            throw ExceptionUtils.mpe("Failed to process, Error SQL: %s", e.getCause(), new Object[]{sql});
        }
    }

    public String parserMulti(String sql, Object obj) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("original SQL: " + sql);
        }

        try {
            StringBuilder sb = new StringBuilder();
            Statements statements = JsqlParserGlobal.parseStatements(sql);
            int i = 0;

            for (Iterator var6 = statements.getStatements().iterator(); var6.hasNext(); ++i) {
                Statement statement = (Statement) var6.next();
                if (i > 0) {
                    sb.append(";");
                }

                sb.append(this.processParser(statement, i, sql, obj));
            }

            return sb.toString();
        } catch (JSQLParserException var8) {
            JSQLParserException e = var8;
            throw ExceptionUtils.mpe("Failed to process, Error SQL: %s", e.getCause(), new Object[]{sql});
        }
    }

    protected String processParser(Statement statement, int index, String sql, Object obj) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("SQL to parse, SQL: " + sql);
        }

        if (statement instanceof Insert) {
            this.processInsert((Insert) statement, index, sql, obj);
        } else if (statement instanceof Select) {
            this.processSelect((Select) statement, index, sql, obj);
        } else if (statement instanceof Update) {
            this.processUpdate((Update) statement, index, sql, obj);
        } else if (statement instanceof Delete) {
            this.processDelete((Delete) statement, index, sql, obj);
        }

        sql = statement.toString();
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("parse the finished SQL: " + sql);
        }

        return sql;
    }

    protected void processInsert(Insert insert, int index, String sql, Object obj) {
        throw new UnsupportedOperationException();
    }

    protected void processDelete(Delete delete, int index, String sql, Object obj) {
        throw new UnsupportedOperationException();
    }

    protected void processUpdate(Update update, int index, String sql, Object obj) {
        throw new UnsupportedOperationException();
    }

    protected void processSelect(Select select, int index, String sql, Object obj) {
        throw new UnsupportedOperationException();
    }
}
